Skip to content

Add tracing to data race functions #4523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Stypox
Copy link
Contributor

@Stypox Stypox commented Aug 11, 2025

This PR adds tracing calls to the Vclocks data race checks.

data_race seem to amount to around 5% of the program time, although given the sheer amount of very short-lived tracing calls I think most of that 5% is spent within the tracing infrastructure. The trace file for analysis below was obtained by running the multithreaded program at the bottom with n=100 and thread_count=5; let me know if there is a better multithreaded example I could try where data race checks are more prominent.

The following table was obtained with the SQL query below in ui.perfetto.dev, on the trace file mentioned above.

select "TOTAL PROGRAM DURATION" as name, count(*), max(ts + dur) as "sum(dur)", 100.0 as "%", null as "min(dur)", null as "max(dur)", null as "avg(dur)", null as "stddev(dur)" from slices union select "TOTAL OVER ALL SPANS (excluding events)" as name, count(*), sum(dur), cast(cast(sum(dur) as float) / (select max(ts + dur) from slices) * 1000 as int) / 10.0 as "%", min(dur), max(dur), cast(avg(dur) as int) as "avg(dur)", cast(sqrt(avg(dur*dur)-avg(dur)*avg(dur)) as int) as "stddev(dur)" from slices where parent_id is null and name != "frame" and name != "step" and dur > 0 union select name, count(*), sum(dur), cast(cast(sum(dur) as float) / (select max(ts + dur) from slices) * 1000 as int) / 10.0 as "%", min(dur), max(dur), cast(avg(dur) as int) as "avg(dur)", cast(sqrt(avg(dur*dur)-avg(dur)*avg(dur)) as int) as "stddev(dur)" from slices where parent_id is null and name != "frame" and name != "step" group by name order by sum(dur) desc, count(*) desc
image

This is the partitioning of calls among the various data_race spans being traced (even nested ones are included here, that's why the count(*) don't add up to 498874. It was obtained with the SQL query below on the same trace file as before.

select args.string_value as name, count(*), sum(dur), min(dur), max(dur), cast(avg(dur) as int) as "avg(dur)", cast(sqrt(avg(dur*dur)-avg(dur)*avg(dur)) as int) as "stddev(dur)" from slices inner join args USING (arg_set_id) where args.key = "args." || slices.name and name = "data_race" group by args.string_value order by count(*) desc
image
Rust code that was used as a benchmark to pass to Miri to collect traces
fn main() {
    let n: usize = std::env::args().nth(1).unwrap().parse().unwrap();
    let thread_count: usize = std::env::args().nth(2).unwrap().parse().unwrap();

    let threads = (0..thread_count).map(|_| std::thread::spawn(move || {
        let mut v = (0..n).into_iter().collect::<Vec<_>>();
        for i in &mut v {
            *i += 1;
        }
    })).collect::<Vec<_>>();

    for thread in threads {
        thread.join().unwrap();
    }
}

@rustbot
Copy link
Collaborator

rustbot commented Aug 11, 2025

Thank you for contributing to Miri!
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Waiting for a review to complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants